define(["jquery", "easy-admin","xm-select"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'mall.manager/index',
        door_url: 'mall.door/index',
        apply_url: 'mall.manager/apply',
        goods_url: 'mall.goods/index?type=1',
        add_url: 'mall.manager/add',
        edit_url: 'mall.manager/edit',
        delete_url: 'mall.manager/delete',
        export_url: 'mall.manager/export',
        modify_url: 'mall.manager/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                height:'full-50',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id',search: false},
                    {field: 'title', title: '商家名称'},
                    {field: 'logo', minWidth: 80, title: '商家logo', search: false, templet: ea.table.image},
                    {field: 'realname', title: '联系人',search: false},
                    {field: 'mobile', title: '联系电话'},
                    {field: 'status', search: 'select', selectList: {0: '待审核', 1: '通过审核',2:'未通过'}, title: '审核状态'},
                    {field: 'create_time', title: '添加时间',search: 'range'},
                    {
                        title: '操作',
                        width: 300,
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '审核',
                                url: init.apply_url,
                                method: 'open',
                                auth: 'apply',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                                show:[
                                    {"name":"status","value":"0"}
                                ]
                            },{
                                text: '商家门店',
                                url: init.door_url,
                                method: 'open',
                                auth: 'door',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                            },{
                                text: '商家商品',
                                url: init.goods_url,
                                method: 'open',
                                auth: 'goods',
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                            },
                            {
                                text: '编辑',
                                url: init.edit_url,
                                method: 'open',
                                auth: 'edit',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                                extend: 'data-full="true"',
                            }],'delete'
                        ]
                    },
                ]],
            });
            ea.listen();
        },
        add: function () {
            var demo1 = xmSelect.render({
                el: '#userdemo',
                on: function (data) {
                    var arr = data.arr;
                    let ids=[];
                    if (arr.length > 0) {
                        for (let i = 0; i < arr.length; i++) {
                            $("#openid").val(arr[i].value);
                        }
                    }
                },
                autoRow: true,
                toolbar: { show: true },
                filterable: true,
                remoteSearch: true,

                remoteMethod: function(val, cb, show){
                    $.ajax({
                        type: "GET",
                        url: "/admin/mall.manager/getNobingUserlist",
                        data: {keyword: val},
                        dataType: "json",
                        success: function (data) {
                            console.log(data);
                            cb(data.data);
                        }
                    })
                }
            })
            ea.listen();
        },
        edit: function () {
            var demo1 = xmSelect.render({
                el: '#userdemo',
                on: function (data) {
                    var arr = data.arr;
                    let ids=[];
                    if (arr.length > 0) {
                        for (let i = 0; i < arr.length; i++) {
                            $("#openid").val(arr[i].value);
                        }
                    }
                },
                autoRow: true,
                toolbar: { show: true },
                filterable: true,
                remoteSearch: true,

                remoteMethod: function(val, cb, show){
                    $.ajax({
                        type: "GET",
                        url: "/admin/mall.manager/getUserlist",
                        data: {keyword: val},
                        dataType: "json",
                        success: function (data) {
                            console.log(data);
                            cb(data.data);
                        }
                    })
                }
            })
            if($("#openid").val()!=''){
                demo1.setValue([{value:$("#openid").val(),name:$("#nickName").val()}]);
            }

            ea.listen();
        },
        apply: function () {
            ea.listen();
        },
    };
    return Controller;
});